package com.qding.park.common.utils.rchl;



public class RchlStringUtil {

	
	public static boolean isEmpty(CharSequence cs){
	    return (cs == null) || (cs.length() == 0);
	 }

	 public static boolean isNotEmpty(CharSequence cs){
	   return !isEmpty(cs);
	 }
	 
	 public static  String hiddenString(String source,int formIndex,int length){
			if(isEmpty(source)){
				return source;
			}else{
				int srcLen = source.length();
				if(formIndex >srcLen 
						|| length > srcLen){
					return source;
				}
				
				StringBuffer sb = new StringBuffer();
				sb.append(source.substring(0, formIndex));
				for(int i=0;i<length;i++){
					sb.append("*");
				}
				sb.append(source.substring(formIndex+length, srcLen));
				
				return sb.toString();
			}
		} 
	 
	 public static String createNeedLengthString(String sourceStr,int need){
			StringBuffer sb = new StringBuffer();
			
			int addLen = 0;
			if(sourceStr  != null){
				int sourceLen = sourceStr.getBytes().length;
				
				if(sourceLen > need){
					try {
						throw new Exception("source str length:"+sourceLen+"  >  need length:"+need+",source data:"+sourceStr);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}else{
					addLen = need - sourceLen;
					sb.append(sourceStr);
				}
			}else{
				addLen=need;
			}
			
			for(int i=0;i<addLen;i++){
				sb.append(" ");
			}
			
			return sb.toString();
		}


}
